from enum import Enum


class BaseEnum(Enum):

    def __init__(self, code, text):
        self.code = code
        self.text = text

    @classmethod
    def get_enum_text(cls):
        values = []
        for item in cls.__members__.values():
            values.append(item.text)
        return values

    @classmethod
    def get_enum_code(cls):
        values = []
        for item in cls.__members__.values():
            values.append(item.code)
        return values

    @classmethod
    def get_enum_items(cls):
        values = []
        for item in cls.__members__.values():
            values.append({'code': item.code, 'text': item.text})
        return values

    @classmethod
    def code_to_text(cls, code: int, default='') -> str:
        for item in cls.__members__.values():
            if code == item.code:
                return item.text
        return default

    @classmethod
    def text_to_code(cls, text: str, default=None) -> str:
        for item in cls.__members__.values():
            if text == item.text:
                return item.code
        return default

